//
//  BiGpsDBManager.m
//  TrunkIndustryManageSystem
//
//  Created by WT_lyy on 15/5/3.
//  Copyright (c) 2015年 李璐西. All rights reserved.
//

#import "BiGpsDBManager.h"

#import "FMDatabase.h"
__strong static BiGpsDBManager * g_singleInstance = nil;

@implementation BiGpsDBManager

+(BiGpsDBManager *)shareInstance{
    
    dispatch_once_t sigle = 0;
    
    dispatch_once(&sigle,^{
        g_singleInstance = [[BiGpsDBManager alloc] init];
    });
    return g_singleInstance;

}


- (id)init{

    self = [super init];
    
    if (self) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"gps" ofType:@"db"];
        _database = [FMDatabase databaseWithPath:path];
        [_database open];
    }
    
    return self;
}

-(CLLocationCoordinate2D)zzTransGPS:(CLLocationCoordinate2D)yGps{
    
    int TenLat=0;
    int TenLog=0;
    TenLat = (int)(yGps.latitude*10);
    TenLog = (int)(yGps.longitude*10);

   NSString *sql = [[NSString alloc]initWithFormat:@"select offLat,offLog from gpsT where lat=%d and log = %d",TenLat,TenLog];
    
    int offLat=0;
    int offLog=0;
    
    FMResultSet *set = [_database executeQuery:sql];
    while ([set next]) {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setObject:[set stringForColumn:@"offLat"] forKey:@"offLat"];
        [dict setObject:[set stringForColumn:@"offLog"] forKey:@"offLog"];
        
    }

    yGps.latitude = yGps.latitude+offLat*0.01;
    yGps.longitude = yGps.longitude + offLog*0.01;
    return yGps;
    
    
}



@end
